/**
 * SlideShow is an Android Custom View that displays a set of slides.
 *
 * Copyright (C) 2008-2009 Free Beachler
 * <http://code.google.com/p/android-slide-show/>
 *
 * SlideShow is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * SlideShow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SlideShow.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.freebeachler.android.component.slideshow;

import java.net.URL;

import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Transformation;

/**
 * @author freebeachler
 *
 */
public abstract class Slide
    implements ISlide {

    public static final int SLIDE_DIRECTION_FORWARD = 0;
    public static final int SLIDE_DIRECTION_BACKWARD = 1;
    
    /**
     * Flag if the slide is loaded or not.
     */
    private boolean slideLoaded;

    /**
     * uri of this slide - either uri or drawable can be active.
     */
    private String slideTitle;
    
    /**
     * uri of this slide - either uri or drawable can be active.
     */
    private URL slideUri;
    
    /**
     * uri that can be linked to this slide for onpress/touch events
     */
    private URL slideLinkUri;
    
    /**
     * animation to apply when hiding slide
     */
    private Animation mHideAnimation;
    
    /**
     * animation to apply when showing slide
     */
    private Animation mShowAnimation;
    
    /**
     * holds the transformation generated by 
     * applying the currently running animation
     */
    private Transformation mTransformation;
    
    /**
     * animation callback handler
     */
    private Handler mHandler;
    
    /**
     * @inheritDoc
     */
    public void clearSlide() {
        slideLoaded = false;
        slideTitle = "";
        slideUri = null;
        slideLinkUri = null;
        mHideAnimation = null;
        mShowAnimation = null;
        mTransformation = null;
    }

    /**
     * @inheritDoc
     */
    public URL getSlideUri() {
        return slideUri;
    }

    /**
     * @inheritDoc
     */
    public void setSlideUri(URL slideUri) {
        this.slideUri = slideUri;
    }

    /**
     * @return the slideTitle
     */
    public String getSlideTitle() {
        return slideTitle;
    }

    /**
     * @param slideTitle the slideTitle to set
     */
    public void setSlideTitle(String slideTitle) {
        this.slideTitle = slideTitle;
    }

    /**
     * @return the slideDetailUri
     */
    public URL getSlideDetailUri() {
        return slideLinkUri;
    }

    /**
     * @param slideDetailUri the slideDetailUri to set
     */
    public void setSlideDetailUri(URL slideDetailUri) {
        this.slideLinkUri = slideDetailUri;
    }
    
    /**
     * @inheritDoc
     */
    public void setSlideLoaded(boolean slideLoaded) {
        this.slideLoaded = slideLoaded;
    }
    
    /**
     * @inheritDoc
     */
    public boolean isSlideLoaded() {
        return this.slideLoaded;
    }
    
    /**
     * @inheritDoc
     */
    public Animation getShowAnimation() {
        return mShowAnimation;
    }
    
    /**
     * @inheritDoc
     */
    public void setShowAnimation(Animation anim) {
        mShowAnimation = anim;
    }

    /**
     * @inheritDoc
     */
    public void setShowAnimation(AnimationSet anim) {
        mShowAnimation = anim;
    }

    /**
     * @inheritDoc
     */
    public Animation getHideAnimation() {
        return mHideAnimation;
    }
    
    /**
     * @inheritDoc
     */
    public void setHideAnimation(Animation anim) {
        mHideAnimation = anim;
    }

    /**
     * @inheritDoc
     */
    public void setHideAnimation(AnimationSet anim) {
        mShowAnimation = anim;
    }

    /**
     * @inheritDoc
     */
    public Transformation getTransformation() {
        return mTransformation;
    }

    /**
     * @inheritDoc
     */
    public void setTransformation(Transformation transformation) {
        this.mTransformation = transformation;
    }

    /**
     * @return the handler
     */
    public Handler getHandler() {
        return mHandler;
    }

    /**
     * @param handler the handler to set
     */
    public void setHandler(Handler handler) {
        mHandler = handler;
    }

    /**
     * @inheritDoc
     */
    public boolean hasStarted() {
        return mShowAnimation != null && mShowAnimation.hasStarted();
    }
    
    /**
     * @inheritDoc
     */
    public boolean hasEnded() {
        return mHideAnimation == null || mHideAnimation.hasEnded();
    }
    
    /**
     * @inheritDoc
     */
    public void clearAllAnimations() {
        mShowAnimation = null;
        mHideAnimation = null;
        mTransformation = null;
    }

}
